package app.server.project.main.service.db.dao;

import app.server.project.main.service.db.entity.AccountEntity;
import app.server.project.main.service.db.entity.UserInfoEntity;
import app.server.project.main.service.db.mapper.AccountMapper;
import app.server.project.main.service.db.mapper.UserInfoMapper;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.Objects;

/**
 * @author Administrator
 * @description 针对表【user_info(用户信息表)】的数据库操作Service实现
 * @createDate 2025-01-16 15:25:22
 */
@Repository
public class AccountDao extends ServiceImpl<AccountMapper, AccountEntity> {


    @Cacheable(key = "#email",cacheNames = "app.server.project.main.service.db.dao.AccountDao")
    public AccountEntity getDataByEmail(String email) {
        var data=this.getById(email);
        if (Objects.isNull(data)){
            //缓存没有,就往库中写入一条数据
            data=AccountEntity.of(email, IdUtil.getSnowflakeNextId());
        }
        return data;
    }
}




